package com.example.cab1;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

import android.telephony.TelephonyManager;
import android.telephony.gsm.GsmCellLocation;

public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    
        Button b1 = (Button) findViewById(R.id.toggleButton1);
        ImageView view = (ImageView) findViewById(R.drawable.cab);
        
        b1.setOnClickListener(new OnClickListener() {
			
			public void onClick(View arg0) 
			{
				// TODO Auto-generated method stub
				//get location
				final TelephonyManager telephony = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
				if (telephony.getPhoneType() == TelephonyManager.PHONE_TYPE_GSM) 
				{
				final GsmCellLocation location = (GsmCellLocation) telephony.getCellLocation();
				
				if (location != null) 
					{
					//msg.setText("LAC: " + location.getLac() + " CID: " + location.getCid());
					 Toast toast =Toast.makeText(getApplicationContext(), "LAC: " + location.getLac() + " CID: " + location.getCid(), Toast.LENGTH_LONG);
					 
					 //connect to server
					 
					 HttpClient mClient= new DefaultHttpClient();
					 String mobile="9886317184";
					 try
					 {
						 HttpGet httppost = new HttpGet("http://myapp.zymichost.com/hack2/Test1.php?NUM="+mobile+"&NAME=vivek"+"&LAC="+location.getLac());
						 HttpResponse res = mClient.execute(httppost);
					 }
					 catch (Exception e) {
				            // TODO Auto-generated catch block
									e.printStackTrace();
										}
					 
					 //end connect to server
					 toast.show();


					}
				}
				

			}
		});
    }


    
}
